package com.zq.widget.inverted.game.role.equipment.weapon.gun;

import android.graphics.PointF;
import android.support.v4.content.ContextCompat;
import android.view.animation.AnimationUtils;

import com.zq.widget.inverted.R;
import com.zq.widget.inverted.game.role.RoleGroup;
import com.zq.widget.inverted.game.role.equipment.weapon.gun.bullet.LaserBullet;
import com.zq.widget.inverted.game.role.level.Level;

/**
 * Created by zhangqiang on 2018/4/2.
 */
public class LaserGun extends AbstractGun {

    private long validTime;
    private long startTime;
    private LaserBullet laserBullet ;
    private RoleGroup holder;

    public LaserGun(RoleGroup holder,Level levelProxy, long validTime) {
        super(levelProxy);
        this.validTime = validTime;
        this.holder = holder;
    }

    @Override
    public void compute() {

        if(laserBullet == null){
            laserBullet = new LaserBullet(holder.getContext(), ContextCompat.getColor(holder.getContext(), R.color.colorAccent), 50,300);
            holder.addChild(laserBullet);
        }
        float x = holder.bounds().centerX();
        float y = holder.bounds().top - laserBullet.bounds().height()/2 - 10;
        laserBullet.updateLocation(x,y);
    }

    @Override
    public boolean isValid() {

        long timeMillis = AnimationUtils.currentAnimationTimeMillis();
        if(this.startTime <= 0){
            this.startTime = timeMillis;
        }
        return timeMillis - this.startTime < validTime;
    }

    @Override
    public void onDrop() {
        super.onDrop();
        laserBullet.reduceHp(laserBullet.getHp());
    }

    @Override
    public int priority() {
        return 0;
    }

    @Override
    public PointF shootPoint() {
        return null;
    }
}
